import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:xiecheng_lvyou/model/home_model.dart';

const homeUrl = 'https://www.geekailab.com/io/flutter_app/json/home_page.json';
// https://www.geekailab.com/io/flutter_app/json/travel_page.json


//首页接口
class HomeDao {
  static Future<HomeModel> fetch() async {
    var url =
        Uri.https('www.geekailab.com', 'io/flutter_app/json/home_page.json');
    // var url = Uri(scheme: 'https',host: 'www.geekailab.com',path: 'io/flutter_app/json/home_page.json');

    final response = await http.get(url);
    if (response.statusCode == 200) {
      Utf8Decoder urf8decoder = const Utf8Decoder(); // fix中文乱码
      var result = json.decode(urf8decoder.convert(response.bodyBytes)); //解码

      return HomeModel.fromJson(result);
    } else {
      throw Exception('请求接口失败');
    }
  }
}